<script>
  export default { name: 'TaskPickupPage' }
</script>

<script setup>
  import { computed, ref } from 'vue'
  import { takeDelivery } from '@/apis/task'
  import { onLoad } from '@dcloudio/uni-app'
  import { toast } from '../../utils/utils'

  const query = ref({})
  onLoad((_query) => {
    query.value = _query
  })

  const cargoPickUpPictureList = ref([])
  const cargoPictureList = ref([])

  const disabledSubmitBtn = computed(() => {
    return cargoPickUpPictureList.value.length === 0 || cargoPictureList.value.length === 0
  })

  const submit = async () => {
    await takeDelivery({
      id: query.value.id,
      cargoPictureList: cargoPictureList.value.map((v) => ({ url: v.url })),
      cargoPickUpPictureList: cargoPickUpPictureList.value.map((v) => ({ url: v.url })),
    })

    toast('提货成功，请尽快送达！')

    // setTimeout(() => {
    //   uni.switchTab({
    //     url: '/pages/task/index',
    //   })
    // }, 1500)

    setTimeout(uni.switchTab, 1500, {
      url: '/pages/task/index',
    })
  }
</script>
<template>
  <view class="page-container">
    <view class="receipt-info">
      <uni-file-picker
        :limit="3"
        file-mediatype="image"
        file-extname="png,jpg"
        title="请拍照上传回单凭证"
        v-model="cargoPickUpPictureList"
      ></uni-file-picker>
      <uni-file-picker
        :limit="3"
        file-mediatype="image"
        file-extname="png,jpg"
        title="请拍照上传货品照片"
        v-model="cargoPictureList"
      ></uni-file-picker>
    </view>
    <button :disabled="disabledSubmitBtn" class="button" @click="submit">提交</button>
  </view>
</template>

<style lang="scss" scoped>
  .page-container {
    padding: 30rpx;
  }

  .receipt-info {
    min-height: 600rpx;
    background-color: #fff;
    padding: 20rpx 30rpx;
    border-radius: 16rpx;

    ::v-deep .uni-file-picker {
      margin-bottom: 30rpx;
    }
  }

  .button {
    height: 100rpx;
    text-align: center;
    line-height: 100rpx;
    /* #ifdef APP */
    padding-top: 4rpx;
    /* #endif */
    border-radius: 100rpx;
    margin-top: 60rpx;
    color: #fff;
    font-size: $uni-font-size-big;
    background-color: $uni-primary;

    &[disabled],
    &.disabled {
      color: #fff;
      background-color: #fadcd9;
    }
  }
</style>
